package com.bestcem.xm.qdes.controller;

import com.alibaba.fastjson.JSONObject;
import com.bestcem.xm.common.core.domain.web.XmResultJson;
import com.bestcem.xm.qdes.service.QdesProjectService;
import com.bestcem.xm.qdes.service.UploadFileInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author SXS
 */
@Slf4j
@Api(tags = "问卷")
@RestController
@RequiredArgsConstructor
public class QdesProjectController {

    private @NonNull QdesProjectService projectService;
    private @NonNull UploadFileInfoService uploadFileInfoService;

    @ApiOperation(value = "查询当前问卷问卷端所使用的外部参数")
    @GetMapping("/qdes/project/ext_params")
    public XmResultJson<Object> getProjectExtParams(@RequestParam("project_id") String projectId) {
        return projectService.getProjectExtParams(projectId);
    }

    @ApiOperation(value = "问卷编辑-图片上传")
    @PostMapping("/upload/")
    public XmResultJson<JSONObject> postUpload(@RequestParam("file") MultipartFile file,
                                               @RequestParam("systemCode") String systemCode) throws Exception {
        return XmResultJson.success(uploadFileInfoService.postUpload(file, systemCode));
    }

    @ApiOperation(value = "问卷编辑-图片修改")
    @PutMapping("/upload/{id:[a-fA-F0-9]{24}}")
    public XmResultJson<String> putUpload(@RequestParam("file") MultipartFile file,
                                          @PathVariable String id) throws Exception {
        return XmResultJson.success(uploadFileInfoService.putUpload(file, id));
    }

    @ApiOperation(value = "奖励上传微信(或者支付宝)二维码")
    @GetMapping("/upload/{id:[a-fA-F0-9]{24}}/qrcode/")
    public XmResultJson<Object> getFilemapQrcode(@RequestParam("id") String fileMapId) {
        return uploadFileInfoService.getFilemapQrcode(fileMapId);
    }
}
